package cn.iocoder.yudao.module.product.controller.app.spu.vo;

import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
import cn.iocoder.yudao.module.product.enums.spu.DeliveryMethodEnum;
import cn.iocoder.yudao.module.product.enums.spu.ProductSkuStatusEnum;
import cn.iocoder.yudao.module.product.enums.spu.ProductTypeEnum;
import cn.iocoder.yudao.module.product.enums.spu.RechargeMethodEnum;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

@Schema(description = "用户 App - 商品 SPU 明细 Response VO")
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AppProductSpuDetailRespVO extends AppDenominationVO{

    @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Long id;

    // ========== 基本信息 =========

    @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
    private String name;

    @Schema(description = "商品简介", example = "我是一个快乐简介")
    private String introduction;

    @Schema(description = "商品详情（中文）", example = "清凉小短袖详情")
    private String description;

    @Schema(description = "商品详情（英文）", example = "清凉小短袖详情")
    private String descriptionEn;

    @Schema(description = "商品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Long categoryId;

    @Schema(description = "商品封面图", requiredMode = Schema.RequiredMode.REQUIRED)
    private String picUrl;

    @Schema(description = "商品轮播图", requiredMode = Schema.RequiredMode.REQUIRED)
    private List<String> sliderPicUrls;

    // ========== 营销相关字段 =========

    // ========== SKU 相关字段 =========

    @Schema(description = "规格类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
    private Boolean specType;

    @Schema(description = "库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
    private Integer stock;

    /**
     * SKU 数组
     */
    private List<Sku> skus;

    // ========== 统计相关字段 =========

    @Schema(description = "商品销量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
    private Integer salesCount;

    @Schema(description = "用户 App - 商品 SPU 明细的 SKU 信息")
    @Data
    public static class Sku {

        @Schema(description = "商品 SKU 编号", example = "1")
        private Long id;

        /**
         * 商品属性数组
         */
        private List<AppProductPropertyValueDetailRespVO> properties;

        @Schema(description = "销售价格，单位：分", example = "1024")
        private Integer price;

        @Schema(description = "图片地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
        private String picUrl;

        @Schema(description = "库存", example = "1")
        private Integer stock;

        @Schema(description = "商品重量", example = "1") // 单位：kg 千克
        private Double weight;

        @Schema(description = "商品体积", example = "1024") // 单位：m^3 平米
        private Double volume;

        // ========== 新增SKU 相关字段 =========

        @Schema(description = "商品SKU名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉小短袖")
        @NotEmpty(message = "商品SKU名字不能为空")
        private String name;

        @Schema(description = "商品SKU简介描述", example = "清凉小短袖")
        private String introduction;

        @Schema(description = "排序字段", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "排序字段不能为空")
        private Integer sort;

        @Schema(description = "sku状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
        @NotNull(message = "sku状态不能为空")
        @InEnum(ProductSkuStatusEnum.class)
        private Integer status;

        @Schema(description = "最低起购件数", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "最低起购件数不能为空")
        private Integer minPurchaseQuantity;

        @Schema(description = "最高起购件数", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "最高起购件数不能为空")
        private Integer maxPurchaseQuantity;

        @InEnum(DeliveryMethodEnum.class)
        @Schema(description = "发货方式")
        private Integer deliveryMethod;

        @Schema(description = "面值描述")
        private String denomination;

        @Schema(description = "固定面值")
        private Integer denominationFixed;

        @Schema(description = "是否自定义面值")
        private Boolean customDenomination;

        @Schema(description = "最小自定义面值，单位：分")
        private Integer minCustomDenomination;

        @Schema(description = "最大自定义面值，单位：分")
        private Integer maxCustomDenomination;

        @Schema(description = "卡密商品编号")
        private String cardKeyProductNo;

        @Schema(description = "支付价格（使用结算货币），单位：分", example = "1024")
        private Integer paymentPrice;

        @Schema(description = "支付货币", example = "USD")
        private String paymentCurrency;

        @Schema(description = "折扣率")
        private String discountRate;

        @Schema(description = "折扣率（不考虑团购）")
        private String discountRateExcludeCombination;

        @Schema(description = "最小面值卡的价格")
        private Integer minDenominationCardPrice;

        @Schema(description = "最大面值卡的价格")
        private Integer maxDenominationCardPrice;

        @Schema(description = "最小面值支付价格")
        private Integer minDenominationPaymentPrice;

        @Schema(description = "最大面值支付价格")
        private Integer maxDenominationPaymentPrice;

        // ========== 新增eSim SKU 相关字段 =========

        @Schema(description = "eSim流量大小")
        private Integer esDataAllowanceMb;

        @Schema(description = "eSim有效期")
        private Integer esValidityPeriodDays;

        @Schema(description = "eSim商品id")
        private String esProductId;
    }

    // ========== 新增SPU 相关字段 =========

    @Schema(description = "是否为虚拟商品", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
    @NotNull(message = "是否为虚拟商品不能为空")
    private Boolean virtualProduct;

    @InEnum(ProductTypeEnum.class)
    @Schema(description = "商品类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    @NotNull(message = "商品类型不能为空")
    private Integer productType;

    @Schema(description = "所属区域")
    private String region;

    @InEnum(RechargeMethodEnum.class)
    @Schema(description = "充值方式")
    private Integer rechargeMethod;

    @Schema(description = "自定义用户输入框")
    private List<Integer> customUserInput;

    @Schema(description = "SPU基础属性数组")
    private List<AppProductPropertyValueDetailRespVO> properties;

    @Schema(description = "配送方式数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private List<Integer> deliveryTypes;

    @Schema(description = "物流配置模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "111")
    @ExcelProperty("物流配置模板编号")
    private Long deliveryTemplateId;

    @Schema(description = "录入货币", example = "USD")
    private String currencyCode;

    @Schema(description = "售卖渠道, 售卖渠道, 0: 通用，1：支付宝，2：微信")
    private Integer salesChannel;

    @Override
    public Long getSpuId() {
        return id;
    }

    @Override
    public String getCardCurrencyCode() {
        return currencyCode;
    }
}
